/*
 * Save.java
 *
 * Created on May 23, 2006, 1:44 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author Timoz
 */
import java.io.*;
import java.util.*;

public class Save implements Serializable {
    static FileOutputStream fos;
    static ObjectOutputStream oos;
    
    /** Creates a new instance of Save */
    public Save() {
    }
    
    public static void save (String formTitle,MyFrame.DesignPanel panel,ArrayList<MyComponentContainer> componentList, String tableName)
    {
            String curDir = System.getProperty("user.dir");
            try
            {
                // Create a directory; all non-existent ancestor directories are
                // automatically created
                boolean success = (new File(curDir+"/Forms/"+MainWindow.host+"/"+MainWindow.selectedDatabase)).mkdirs();
                if (!success) {
                    // Directory creation failed
                }
                fos = new FileOutputStream(curDir+"/Forms/"+MainWindow.host+"/"+MainWindow.selectedDatabase+"/"+formTitle);
                oos = new ObjectOutputStream (fos);
                oos.writeObject(panel.getSize());
                fos = new FileOutputStream(curDir+"/Forms/"+MainWindow.host+"/"+MainWindow.selectedDatabase+"/"+formTitle,true);
                oos.writeObject(panel.getBackground());
                oos.writeObject(componentList);
                oos.writeObject(tableName);
                fos.close();
                oos.close();
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
            }
    }
}
